/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication3;

import java.util.HashMap;
import java.util.ListIterator;
import java.util.Map;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 *
 * @author andrea
 */
public class ScanningInformazioni {

    private String value;
    private String attributo;
    private String testo;
    private static Map<String, Integer> resources = new HashMap<String, Integer>();
    private static Map<String, String> resources2 = new HashMap<String, String>();

    public ScanningInformazioni(String text) {
        this.testo = text;
    }

    public void ricavaOra() {

        //this.testo = text;

        Document jsoupDc = Jsoup.parse(testo);
        Elements indirizzo = jsoupDc.select("span#tp1");
        Element ora_server = indirizzo.first();
        attributo = ora_server.text();
        System.out.println("Ora: " + ora_server.text());
    }

    public void ricavaInfo() {
        //this.testo = text;

        Document jsoupDoc = Jsoup.parse(testo);
        Elements risorse = jsoupDoc.select("ul#res>li");


        for (ListIterator<Element> it = risorse.listIterator(); it.hasNext();) {
            int value = Integer.parseInt(it.next().text().split("/")[0]);
            resources.put("Legno", value);
            System.out.println("Legno: " + value);
            if (it.hasNext()) {
                value = Integer.parseInt(it.next().text().split("/")[0]);
                resources.put("Argilla", value);
                System.out.println("Argilla: " + value);
            }
            if (it.hasNext()) {
                value = Integer.parseInt(it.next().text().split("/")[0]);
                resources.put("Ferro", value);
                System.out.println("Ferro: " + value);
            }
            if (it.hasNext()) {
                value = Integer.parseInt(it.next().text().split("/")[0]);
                resources.put("Grano", value);
                System.out.println("Grano: " + value);
            }
            if (it.hasNext()) {
                value = Integer.parseInt(it.next().text().split("/")[0]);
                resources.put("Saldo Grano", value);
                System.out.println("Saldo Grano: " + value);
            }
        }
        for (Element risorsa : risorse) {
            risorsa = risorsa.select("span.value").first();
            System.out.println(risorsa.text());
        }


    }

    public void ricavaLivelloRisorse() {

        Document jsoupDoc = Jsoup.parse(testo);
        Elements risorse = jsoupDoc.select("div#village_map>div");

        for (ListIterator<Element> it = risorse.listIterator(); it.hasNext();) {
            if (it.hasNext()) {
                value = it.next().text().split("/")[0];
                resources2.put("Livello", value);
                System.out.println("Livello: " + value);
            }

        }

    }
    


}
